﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//Please add references
using System.Data.OracleClient;
namespace TierApplication
{
    public partial class T_ORDER
    {
        public DataSet SP_GET_ORDERLIST(string ac_where)
        {
            OracleParameter[] parameters =  {
                new OracleParameter("ac_where",OracleType.VarChar,4000),
                new OracleParameter("REFCURSOR",OracleType.Cursor)
                                            };
            parameters[0].Value = ac_where;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[1].Direction = ParameterDirection.Output;

            DataSet ds = DbHelperOra.RunProcedure("SP_GET_ORDERLIST", parameters, "CardList");
            return ds;
        }
        //根据订单编号查询订单明细
        public DataSet GetOrderDetailListByOrderID(string sOrderID)
        {
            return GetOrderDetailList(" and OrderID='" + sOrderID + "'");
        }

        public DataSet GetOrderDetailList(string ac_where)
        {
            OracleParameter[] parameters =  {
                new OracleParameter("ac_where",OracleType.VarChar,4000),
                new OracleParameter("REFCURSOR",OracleType.Cursor)
                                            };
            parameters[0].Value = ac_where;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[1].Direction = ParameterDirection.Output;

            DataSet ds = DbHelperOra.RunProcedure("SP_GET_ORDER_DETAIL_LIST", parameters, "OrderDetailList");
            return ds;
        }

        //根据订单查询卡明细
        public DataSet GetOrderCardListByOrderID(string sOrderID)
        {
            return GetOrderCardList(" and A.OrderID='" + sOrderID + "'");
        }

         public DataSet GetOrderCardList(string ac_where)
        {
            OracleParameter[] parameters =  {
                new OracleParameter("ac_where",OracleType.VarChar,4000),
                new OracleParameter("REFCURSOR",OracleType.Cursor)
                                            };
            parameters[0].Value = ac_where;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[1].Direction = ParameterDirection.Output;

            DataSet ds = DbHelperOra.RunProcedure("SP_GET_ORDER_CARD_LIST", parameters, "OrderCardList");
            return ds;
        }

         public void SELLCARD(string AccoundID,ref int ai_result,ref string ac_orderid, ref string ac_result)
         {
             OracleParameter[] parameters =  {
                new OracleParameter("AC_ACCOUNTID",OracleType.VarChar,50),
                new OracleParameter("AI_RESULT",OracleType.VarChar,100),
                new OracleParameter("AC_ORDERID",OracleType.VarChar,50),
                new OracleParameter("AC_RESULT",OracleType.VarChar,50)
                                            };
             parameters[0].Value = AccoundID;
             parameters[0].Direction = ParameterDirection.Input;
             parameters[1].Direction = ParameterDirection.Output;
             parameters[2].Direction = ParameterDirection.Output;
             parameters[3].Direction = ParameterDirection.Output;
             try
            {
                OracleCommand cmd = DbHelperOra.RunProcedureReturnCammand("SP_SELLCARD", parameters);
                ai_result = int.Parse(cmd.Parameters["AI_RESULT"].Value.ToString());
                ac_orderid = cmd.Parameters["AC_ORDERID"].Value.ToString();
                ac_result = cmd.Parameters["AC_RESULT"].Value.ToString();

            }
            catch (Exception e)
            {
                ai_result = -1;
                ac_result = "调用后台过程错误,错误原因为：" + TierService.PageValidate.RemoveChr10And13(e.Message);
            }
         }

         public DataSet GetOrderForAccount(string strWhere)
         {
             StringBuilder sb = new StringBuilder();
             sb.Append(" select a.* ");
             sb.Append(" ,(Select codename From c_Orderstatus t Where t.Codeid = a.Orderstatus) Statusname ");
             sb.Append(" ,(Select accountname From t_account t Where t.accountid=a.accountid  ) accountname  ");
             sb.Append(" from t_order a ");
             sb.Append(" where 1=1 "+strWhere);
             DataSet ds = DbHelperOra.Query(sb.ToString());
             return ds;
         }

         public void CancelOrder(string AC_ORDERID, ref int ai_result, ref string ac_result)
         {
             OracleParameter[] parameters =  {
                new OracleParameter("AC_ORDERID",OracleType.VarChar,50),
                new OracleParameter("AI_RESULT",OracleType.VarChar,100),
                new OracleParameter("AC_RESULT",OracleType.VarChar,50)
                                            };
             parameters[0].Value = AC_ORDERID;
             parameters[0].Direction = ParameterDirection.Input;
             parameters[1].Direction = ParameterDirection.Output;
             parameters[2].Direction = ParameterDirection.Output;
             try
             {
                 OracleCommand cmd = DbHelperOra.RunProcedureReturnCammand("SP_SELLCARD_CANCEL_ORDER", parameters);
                 ai_result = int.Parse(cmd.Parameters["AI_RESULT"].Value.ToString());
                 ac_result = cmd.Parameters["AC_RESULT"].Value.ToString();

             }
             catch (Exception e)
             {
                 ai_result = -1;
                 ac_result = "调用后台过程错误,错误原因为：" + TierService.PageValidate.RemoveChr10And13(e.Message);
             }
         }
    }
}

